<?php

namespace app\home\behavior;

use think\Request;

class MyLog
{
    public function run(&$params)
    {
        $admin_login_status = session("admin_login_status");
        $user_id = session("user_id");
        $user_name = session("user_name");

        if ($admin_login_status != 'OK') {
            return;
        }
        if (empty($user_id)) {
            return;
        }

        $request = Request::instance();
        $action = $request->action();
        if (in_array($action, ['upload', 'do_login', 'getData', 'orderList', 'list', 'detail', 'index', 'planList'])) {
            return;
        }

        $data = array(
            'pathinfo' => Request()->pathinfo(),
            'module' => $request->module(),
            'action' => $action,
            'user_id' => $user_name . '_' . $user_id,
            'ip' => $_SERVER["REMOTE_ADDR"],
            'request_param' => json_encode($request->param()),
            'response_data' => json_encode($params->getData())
        );

        db('my_log')->insert($data);
    }
}
